package com.cari.oa.dao;

import java.util.List;

import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import com.cari.oa.domain.MarketProjectCommentEntity;

@Repository
@SuppressWarnings("unchecked")
public class MarketProjectCommentDao extends BaseDao<MarketProjectCommentEntity> {
	
	/**
     * 根据项目id获取项目留言列表
     * @param enname 系统用户英文名
     * @return 系统实体对象
     */
    public List<MarketProjectCommentEntity> getListByID(String id) {
        Query query = getSession().createQuery("from MarketProjectCommentEntity where projectId = :projectId order by createTime desc");
        query.setString("projectId", id);
        return (List<MarketProjectCommentEntity>)query.list();
    }
    
    /**
     * 获取最新留言时间及其相关项目id
     * @return
     * guotingting 2013-1-24 下午3:13:26
     */
    public List<MarketProjectCommentEntity> getMaxDateList() {
    	StringBuilder str = new StringBuilder();
    	str.append("SELECT max(id) as id, project_id, max(user_enname) as user_enname, max(user_cnname) as user_cnname, max(content) as content,");
    	str.append("max(create_time) as create_time from t_marketproject_comment group by project_Id");
        Query query = getSession().createSQLQuery(str.toString()).addEntity(MarketProjectCommentEntity.class);
        return (List<MarketProjectCommentEntity>)query.list();
    }

}
